package com.rimi.service.impl;

import com.rimi.bean.Menu;
import com.rimi.cache.AdminCache;
import com.rimi.controller.IndexController;
import com.rimi.dao.MenuDao;
import com.rimi.service.MenuService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * InnoDB free: 11264 kB 服务实现类
 * </p>
 *
 * @author sky
 * @since 2018-06-06
 */
@Service
public class MenuServiceImpl extends ServiceImpl<MenuDao, Menu> implements MenuService {


    @Autowired
    private MenuService menuService;

    @Autowired
    private AdminCache adminCache;

    /*从redis查询菜单列表*/
    public List<Menu> getMenuList(){
        List<Menu> menus = adminCache.getCacheList("menus",Menu.class);
        //缓存中是否有数据
        if(menus!=null&&!menus.isEmpty()){
            return menus;
        }
        //如果有数据
        List<Menu> menus1 = menuService.selectList(null);
        //将查询结果缓存到redis中
        adminCache.addCacheList("menus", menus1);
        return menus1;
    }

}
